package kr.or.kead.ui.meun;

import java.awt.event.ActionEvent;

import javax.swing.JFrame;

import kr.or.kead.domain.Auth;
import kr.or.kead.domain.InfoStudent;
import kr.or.kead.domain.Professor;
import kr.or.kead.service.DaoAuth;
import kr.or.kead.service.DaoInfoStudent;
import kr.or.kead.service.DaoProfessor;
import kr.or.kead.service.DaoTable;
import kr.or.kead.ui.Login;
import kr.or.kead.ui.MainFrame;
import kr.or.kead.ui.insert_update.ProfessorUpdate;
import kr.or.kead.ui.insert_update.StdInsertUpdate;

public class BasicsMgn extends AbsMeun {
	private String email;
	private String pass;
	private int level;
	
	private Auth auth;
	public BasicsMgn(JFrame frame) {
		super(frame,"");
		MainFrame mainFrame = (MainFrame) frame;
		auth = mainFrame.getAuth();
		DaoAuth daoAuth = new DaoAuth();
		email = auth.getEmail();
		level = auth.getLevel();
		pass =daoAuth.selectPasswdByEmail(email);;
		initialize();
	}

	private void initialize() {
		addMenu.setText("개인정보변경");
		delMenu.setText("비밀번호변경");
		updateMenu.setText("로그아웃");
		listMenu.setText("종료");
	}

	@Override
	protected void addMenuActionPerformed(ActionEvent e) {
		DaoTable daoObj;
		switch(level){
		case 1:
			daoObj = new DaoInfoStudent();
			InfoStudent std = (InfoStudent) daoObj.selectTableByEmail(email);
			StdInsertUpdate stdUpdate = new StdInsertUpdate(std);
			stdUpdate.setVisible(true);
			break;
		case 2: case 3:	//교사및 직원
			daoObj = new DaoProfessor();
			Professor professor = (Professor) daoObj.selectTableByEmail(email);
			ProfessorUpdate teacherUpdate = new ProfessorUpdate(professor);
			teacherUpdate.setVisible(true);
			break;
		}
	}

	@Override
	protected void delMenuActionPerformed(ActionEvent e) {
		passwdCheck pc = new passwdCheck(auth);
		pc.setVisible(true);
	}

	@Override
	protected void updateMenuActionPerformed(ActionEvent e) {
		new Login();
		frame.dispose();
	}

	@Override
	protected void listMenuActionPerformed(ActionEvent e) {
		frame.dispose();
	}

}
